// Decompiled on 周六 2月 22 19:31:49 CST 2025 with Zomboid Decompiler v0.1.3 using Vineflower.
package zombie.core.opengl;

import zombie.core.SpriteRenderer;
import zombie.util.Type;

public final class GLState {
    public static final GLState.CAlphaFunc AlphaFunc = new GLState.CAlphaFunc();
    public static final GLState.CAlphaTest AlphaTest = new GLState.CAlphaTest();
    public static final GLState.CBlendFunc BlendFunc = new GLState.CBlendFunc();
    public static final GLState.CBlendFuncSeparate BlendFuncSeparate = new GLState.CBlendFuncSeparate();
    public static final GLState.CColorMask ColorMask = new GLState.CColorMask();
    public static final GLState.CStencilFunc StencilFunc = new GLState.CStencilFunc();
    public static final GLState.CStencilMask StencilMask = new GLState.CStencilMask();
    public static final GLState.CStencilOp StencilOp = new GLState.CStencilOp();
    public static final GLState.CStencilTest StencilTest = new GLState.CStencilTest();

    public static void startFrame() {
        AlphaFunc.setDirty();
        AlphaTest.setDirty();
        BlendFunc.setDirty();
        BlendFuncSeparate.setDirty();
        ColorMask.setDirty();
        StencilFunc.setDirty();
        StencilMask.setDirty();
        StencilOp.setDirty();
        StencilTest.setDirty();
    }

    public abstract static class Base2Ints extends IOpenGLState<GLState.C2IntsValue> {
        GLState.C2IntsValue defaultValue() {
            return new GLState.C2IntsValue();
        }
    }

    public abstract static class Base3Ints extends IOpenGLState<GLState.C3IntsValue> {
        GLState.C3IntsValue defaultValue() {
            return new GLState.C3IntsValue();
        }
    }

    public abstract static class Base4Booleans extends IOpenGLState<GLState.C4BooleansValue> {
        GLState.C4BooleansValue defaultValue() {
            return new GLState.C4BooleansValue();
        }
    }

    public abstract static class Base4Ints extends IOpenGLState<GLState.C4IntsValue> {
        GLState.C4IntsValue defaultValue() {
            return new GLState.C4IntsValue();
        }
    }

    public abstract static class BaseBoolean extends IOpenGLState<GLState.CBooleanValue> {
        GLState.CBooleanValue defaultValue() {
            return new GLState.CBooleanValue(true);
        }
    }

    public abstract static class BaseInt extends IOpenGLState<GLState.CIntValue> {
        GLState.CIntValue defaultValue() {
            return new GLState.CIntValue();
        }
    }

    public abstract static class BaseIntFloat extends IOpenGLState<GLState.CIntFloatValue> {
        GLState.CIntFloatValue defaultValue() {
            return new GLState.CIntFloatValue();
        }
    }

    public static final class C2IntsValue implements IOpenGLState.Value {
        int a;
        int b;

        public GLState.C2IntsValue set(int _a, int _b) {
            this.a = _a;
            this.b = _b;
            return this;
        }

        public boolean equals(Object other) {
            GLState.C2IntsValue c2IntsValue = Type.tryCastTo(other, GLState.C2IntsValue.class);
            return c2IntsValue != null && c2IntsValue.a == this.a && c2IntsValue.b == this.b;
        }

        @Override
        public IOpenGLState.Value set(IOpenGLState.Value other) {
            GLState.C2IntsValue c2IntsValue = (GLState.C2IntsValue)other;
            this.a = c2IntsValue.a;
            this.b = c2IntsValue.b;
            return this;
        }
    }

    public static final class C3IntsValue implements IOpenGLState.Value {
        int a;
        int b;
        int c;

        public GLState.C3IntsValue set(int _a, int _b, int _c) {
            this.a = _a;
            this.b = _b;
            this.c = _c;
            return this;
        }

        public boolean equals(Object other) {
            GLState.C3IntsValue c3IntsValue = Type.tryCastTo(other, GLState.C3IntsValue.class);
            return c3IntsValue != null && c3IntsValue.a == this.a && c3IntsValue.b == this.b && c3IntsValue.c == this.c;
        }

        @Override
        public IOpenGLState.Value set(IOpenGLState.Value other) {
            GLState.C3IntsValue c3IntsValue = (GLState.C3IntsValue)other;
            this.a = c3IntsValue.a;
            this.b = c3IntsValue.b;
            this.c = c3IntsValue.c;
            return this;
        }
    }

    public static final class C4BooleansValue implements IOpenGLState.Value {
        boolean a;
        boolean b;
        boolean c;
        boolean d;

        public GLState.C4BooleansValue set(boolean _a, boolean _b, boolean _c, boolean _d) {
            this.a = _a;
            this.b = _b;
            this.c = _c;
            this.d = _d;
            return this;
        }

        public boolean equals(Object other) {
            GLState.C4BooleansValue c4BooleansValue = Type.tryCastTo(other, GLState.C4BooleansValue.class);
            return c4BooleansValue != null && c4BooleansValue.a == this.a && c4BooleansValue.b == this.b && c4BooleansValue.c == this.c;
        }

        @Override
        public IOpenGLState.Value set(IOpenGLState.Value other) {
            GLState.C4BooleansValue c4BooleansValue = (GLState.C4BooleansValue)other;
            this.a = c4BooleansValue.a;
            this.b = c4BooleansValue.b;
            this.c = c4BooleansValue.c;
            this.d = c4BooleansValue.d;
            return this;
        }
    }

    public static final class C4IntsValue implements IOpenGLState.Value {
        int a;
        int b;
        int c;
        int d;

        public GLState.C4IntsValue set(int _a, int _b, int _c, int _d) {
            this.a = _a;
            this.b = _b;
            this.c = _c;
            this.d = _d;
            return this;
        }

        public boolean equals(Object other) {
            GLState.C4IntsValue c4IntsValue = Type.tryCastTo(other, GLState.C4IntsValue.class);
            return c4IntsValue != null && c4IntsValue.a == this.a && c4IntsValue.b == this.b && c4IntsValue.c == this.c && c4IntsValue.d == this.d;
        }

        @Override
        public IOpenGLState.Value set(IOpenGLState.Value other) {
            GLState.C4IntsValue c4IntsValue = (GLState.C4IntsValue)other;
            this.a = c4IntsValue.a;
            this.b = c4IntsValue.b;
            this.c = c4IntsValue.c;
            this.d = c4IntsValue.d;
            return this;
        }
    }

    public static final class CAlphaFunc extends GLState.BaseIntFloat {
        void Set(GLState.CIntFloatValue cIntFloatValue) {
            SpriteRenderer.instance.glAlphaFunc(cIntFloatValue.a, cIntFloatValue.b);
        }
    }

    public static final class CAlphaTest extends GLState.BaseBoolean {
        void Set(GLState.CBooleanValue cBooleanValue) {
            if (cBooleanValue.value) {
                SpriteRenderer.instance.glEnable(3008);
            } else {
                SpriteRenderer.instance.glDisable(3008);
            }
        }
    }

    public static final class CBlendFunc extends GLState.Base2Ints {
        void Set(GLState.C2IntsValue c2IntsValue) {
            SpriteRenderer.instance.glBlendFunc(c2IntsValue.a, c2IntsValue.b);
        }
    }

    public static final class CBlendFuncSeparate extends GLState.Base4Ints {
        void Set(GLState.C4IntsValue c4IntsValue) {
            SpriteRenderer.instance.glBlendFuncSeparate(c4IntsValue.a, c4IntsValue.b, c4IntsValue.c, c4IntsValue.d);
        }
    }

    public static class CBooleanValue implements IOpenGLState.Value {
        public static final GLState.CBooleanValue TRUE = new GLState.CBooleanValue(true);
        public static final GLState.CBooleanValue FALSE = new GLState.CBooleanValue(false);
        boolean value;

        CBooleanValue(boolean _boolean) {
            this.value = _boolean;
        }

        public boolean equals(Object other) {
            return other instanceof GLState.CBooleanValue && ((GLState.CBooleanValue)other).value == this.value;
        }

        @Override
        public IOpenGLState.Value set(IOpenGLState.Value other) {
            this.value = ((GLState.CBooleanValue)other).value;
            return this;
        }
    }

    public static final class CColorMask extends GLState.Base4Booleans {
        void Set(GLState.C4BooleansValue c4BooleansValue) {
            SpriteRenderer.instance.glColorMask(c4BooleansValue.a ? 1 : 0, c4BooleansValue.b ? 1 : 0, c4BooleansValue.c ? 1 : 0, c4BooleansValue.d ? 1 : 0);
        }
    }

    public static final class CIntFloatValue implements IOpenGLState.Value {
        int a;
        float b;

        public GLState.CIntFloatValue set(int _a, float _b) {
            this.a = _a;
            this.b = _b;
            return this;
        }

        public boolean equals(Object other) {
            GLState.CIntFloatValue cIntFloatValue = Type.tryCastTo(other, GLState.CIntFloatValue.class);
            return cIntFloatValue != null && cIntFloatValue.a == this.a && cIntFloatValue.b == this.b;
        }

        @Override
        public IOpenGLState.Value set(IOpenGLState.Value other) {
            GLState.CIntFloatValue cIntFloatValue = (GLState.CIntFloatValue)other;
            this.a = cIntFloatValue.a;
            this.b = cIntFloatValue.b;
            return this;
        }
    }

    public static class CIntValue implements IOpenGLState.Value {
        int value;

        public GLState.CIntValue set(int a) {
            this.value = a;
            return this;
        }

        public boolean equals(Object other) {
            return other instanceof GLState.CIntValue && ((GLState.CIntValue)other).value == this.value;
        }

        @Override
        public IOpenGLState.Value set(IOpenGLState.Value other) {
            this.value = ((GLState.CIntValue)other).value;
            return this;
        }
    }

    public static final class CStencilFunc extends GLState.Base3Ints {
        void Set(GLState.C3IntsValue c3IntsValue) {
            SpriteRenderer.instance.glStencilFunc(c3IntsValue.a, c3IntsValue.b, c3IntsValue.c);
        }
    }

    public static final class CStencilMask extends GLState.BaseInt {
        void Set(GLState.CIntValue cIntValue) {
            SpriteRenderer.instance.glStencilMask(cIntValue.value);
        }
    }

    public static final class CStencilOp extends GLState.Base3Ints {
        void Set(GLState.C3IntsValue c3IntsValue) {
            SpriteRenderer.instance.glStencilOp(c3IntsValue.a, c3IntsValue.b, c3IntsValue.c);
        }
    }

    public static final class CStencilTest extends GLState.BaseBoolean {
        void Set(GLState.CBooleanValue cBooleanValue) {
            if (cBooleanValue.value) {
                SpriteRenderer.instance.glEnable(2960);
            } else {
                SpriteRenderer.instance.glDisable(2960);
            }
        }
    }
}
